for those out there maybe you've heard about API before, but many of us still don't really know what is API or RESTful API. Today's article will cover-up some API topics.
What is API?
API stands for Application Programming Interface. it is a set of rules that allows programs to talk to each other. The developer creates the API on the server and allows the clients to talk to it.
let's say you're trying to find Superman on Google. So you open up Google and type "Superman" than hit enter and you see a list of information about Superman. An API works in similar ways. You're searching for something and you sending a request to the server and the server sending you back a list of results back.
REST
REST stands for "Representational State Transfer". REST determines how to API looks like. it is a set of rules that developers follow when they create their API/.
for each URL is called a request while the data sent back to you is called a response.
The Anatomy of A Request
the request is made up of four things:
EndPoint
the endpoint we talking about here is the URL that we going to make the request. example when you go to https://api.twitter.com the endpoint is this case is twitter.
Method
GET
This request is used to get a resource from a server. If you perform a GET
request, the server looks for the data you requested and sends it back to you. In other words, a GET
request performs a READ
operation. This is the default request method.
POST
This request is used to create a new resource on a server. If you perform a POST
request, the server creates a new entry in the database and tells you whether the creation is successful. In other words, a POST
request performs an CREATE
operation.
PUT and PATCH
These two requests are used to update a resource on a server. If you perform a PUT
or PATCH
request, the server updates an entry in the database and tells you whether the update is successful. In other words, a PUT
or PATCH
request performs an UPDATE
operation.
DELETE
This request is used to delete a resource from a server. If you perform a DELETE
request, the server deletes an entry in the database and tells you whether the deletion is successful. In other words, a DELETE
request performs a DELETE
operation.
The Headers
the header is divided into 2 parts. there are Request and Response Headers. please check this link for a better understanding of API Headers.
The Data or Body
the data contains information you want to send to the server. when you go to Google and search "superman" you probably will go through:
google.com/?q=superman this 'q' means the query or the value that you wanted to search on Google. this data is only used for POST, PUT, PATCH, or DELETE request. on the body part, the data type could be variative, possibly the data could be written in JSON, XML, etc.
that's all for today, tomorrow we will do the code practices about API using Laravel.